﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.IO;
using Vit.Common;
using Vit.Web.Providers;
using Vit.Web.Models;

namespace Vit.Web.Helpers
{
    public class Theme
    {
        public static string ThemePath(string path)
        {
            return string.Format("/Themes/{0}/{1}", PortalContext.Current.Theme, path);
        }

        public static string SkinPath(string path)
        {
            return string.Format("/Themes/{0}/Skins/{1}/{2}", PortalContext.Current.Theme, PortalContext.Current.Skin, path);
        }

        public static string Layout(string layout)
        {
            return ThemePath(string.Format("Layouts/{0}.cshtml", layout));
        }

        //public static string Page(string layout)
        //{
        //    return ThemePath(string.Format("Pages/{0}.cshtml", layout));
        //}

        public static string Container(string conainer)
        {
            return ThemePath(string.Format("Containers/{0}.cshtml", conainer));
        }

        //public static string Control(string control)
        //{
        //    return ThemePath(string.Format("Controls/{0}.cshtml", control));
        //}

        //public static string Editor(string control)
        //{
        //    return ThemePath(string.Format("Editors/{0}.cshtml", control));
        //}

        public static string Image(string imageFile)
        {
            return SkinPath(string.Format("Images/{0}", imageFile));
        }

        public static string Script(string jsFile)
        {
            return SkinPath(string.Format("Scripts/{0}", jsFile));
        }

        public static string Style(string cssFile)
        {
            return SkinPath(string.Format("Styles/{0}", cssFile));
        }

        public static IEnumerable<string> GetContainers()
        {
            string containerPath = HttpContext.Current.Server.MapPath(ThemePath("Containers"));
            DirectoryInfo dir = new DirectoryInfo(containerPath);
            List<string> containers = new List<string>();
            if (dir.Exists)
            {
                foreach (var file in dir.GetFiles("*.cshtml", SearchOption.TopDirectoryOnly))
                {
                    containers.Add(file.Name.Replace(".cshtml", ""));
                }
            }
            return containers;
        }
    }
}
